/**
 * 该文件是用于创建一个为count组件服务的reducer，reducer本身就是一个函数
 * reducer函数会接到两个参数，分别为之前的状态preState和动作对象action
 */

import {Increment,Decrement} from "./constant.js";

const initState=0;
export default function countReducer(preState=initState,action){
    // console.log(preState);
    const {type,data}=action;
    switch (type) {
        case Increment:
            return preState+data;
        case Decrement:
            return preState-data;
        default:
            return preState;
    };
};